/* eslint-disable */
import {getCookie} from './index';

// headers: {
//   'Content-Type': 'application/x-www-form-urlencoded'
// }
export default async (url, options) => {
  try {
    const token = getCookie('token');
    let res = await fetch(url, {
      headers: {
        token
      },
      ...options
    });
    let {code, data, desc} = await res.json();
    if (code === '0') {
      return data ? JSON.parse(data) : data;
    } else {
      throw desc;
    }
  } catch (e) {
    if (Object.prototype.toString.call(e).indexOf('Error') > -1) {
      throw(e.message);
    } else {
      throw e;
    }
  } finally {}
}